package com.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.beans.Novel;
import com.service.impl.NovelServiceImpl;

@Controller
@RequestMapping("/front")
public class FrontController {
    @Resource
    NovelServiceImpl novelservice;

    @RequestMapping("/shuku")
    public String shuku(String novelname, String noveltype, ModelMap m) {
        if (noveltype != null && !noveltype.equals("")) {
            List<Novel> list1 = novelservice.getNovelType(noveltype);
            m.addAttribute("list", list1);
        } else {
            List<Novel> list = novelservice.getAllNovel();
            m.put("list", list);

            if (novelname != null && !novelname.equals("")) {
                List<Novel> list1 = novelservice.getNovelname(novelname);
                m.addAttribute("list", list1);
            } else {
                m.addAttribute("error", "未查询到响应的数据，请您检查输入的数据名称是否正确~");
            }
        }
        return "front/shuku";
    }

    @RequestMapping("/getxiangqing")
    public String xiangqing(String novelname, ModelMap m, HttpSession session) {
        Novel novel = novelservice.getNovelByName(novelname);
        String userName = (String) session.getAttribute("shelf");
        Integer count = novelservice.getBookByUserName(userName,novelname);
        if (count > 0) {
            m.put("isShow", false);
        } else {
            m.put("isShow", true);
        }
        m.put("novel", novel);
        return "front/xiangqing";
    }

    @RequestMapping("/yuanchuang")
    public String yuanchuang() {
        return "front/yuanchuang";
    }

    @RequestMapping("/shouye")
    public String shouye() {
        return "main";
    }
}
